#include "SettingBar.h"
#include "SettingBarButton.h"

SettingBar::SettingBar(QWidget* parent)
{
	this->m_ui.setupUi(this);
	this->setParent(parent);
	this->resize(parent->width() - 10, parent->height());
	this->move(5, 24);
	this->m_selectConnectButton = new SettingBarButton(QString("connect"), this->m_ui.selectConnectButton);
	this->m_selectShowWindowButton = new SettingBarButton(QString("showWindow"), this->m_ui.selectShowWindowButton);
	this->m_screenButton = new SettingBarButton(QString("screen"), this->m_ui.screenButton);
	this->m_recordingButton = new SettingBarButton(QString("recording"), this->m_ui.recordingButton);
	this->m_stopButton = new SettingBarButton(QString("stop"), this->m_ui.stopButton);
	this->m_recordingButton->disable();
	this->m_stopButton->disable();
	this->connect(this->m_selectConnectButton, &QPushButton::clicked, this, &SettingBar::selectConnectButtonOnClick);
	this->connect(this->m_selectShowWindowButton, &QPushButton::clicked, this, &SettingBar::selectShowWindowButtonOnClick);
	this->connect(this->m_recordingButton, &QPushButton::clicked, this, &SettingBar::recordingButtonOnClick);
	this->connect(this->m_stopButton, &QPushButton::clicked, this, &SettingBar::stopButtonOnClick);
	this->connect(this->m_screenButton, &QPushButton::clicked, this, &SettingBar::screenButtonOnClick);
	this->selectConnectButtonOnClick();
	// this->selectShowWindowButtonOnClick();
}

void SettingBar::selectConnectButtonOnClick() {
	if (!this->m_selectConnectButton->checked()) {
		this->m_selectConnectButton->check();
		this->m_selectShowWindowButton->uncheck();
		emit this->changeMain(QString("connectWindow"));
	}
}

void SettingBar::selectShowWindowButtonOnClick() {
	if (!this->m_selectShowWindowButton->checked()) {
		this->m_selectConnectButton->uncheck();
		this->m_selectShowWindowButton->check();
		emit this->changeMain(QString("playWindow"));
	}
}

void SettingBar::recordingButtonOnClick()
{
	if (this->m_screenButton->checked()) {
		this->m_stopButton->enable();
		this->m_recordingButton->check();
		this->m_recordingButton->disable();
		emit this->record();
	}
}

void SettingBar::stopButtonOnClick()
{
	if (this->m_screenButton->checked()) {
		this->m_stopButton->disable();
		this->m_recordingButton->enable();
		this->m_recordingButton->uncheck();
		emit this->stopRecord();
	}
}

void SettingBar::screenButtonOnClick()
{
	if (this->m_screenButton->checked()) {
		this->m_screenButton->uncheck();
		emit this->stopScreen();
		this->m_recordingButton->disable();
	}
	else {
		this->m_screenButton->check();
		emit this->screenWindow(0);
		this->m_recordingButton->enable();
	}
	
}

SettingBar::~SettingBar()
{
	delete this->m_selectConnectButton;
	delete this->m_selectShowWindowButton;
	delete this->m_recordingButton;
	delete this->m_stopButton;
	delete this->m_screenButton;
}
